<template>
<h1>猜数字练习</h1>
  <input type="text" placeholder="请输入1~100之间的整数" v-model="num">
  <button @click="guess()">猜一猜</button>
  <h3>结果：{{result}}</h3>
</template>

<script setup>
import {ref} from "vue";
let count=0;
const num=ref('')
const r=parseInt(Math.random()*100+ 1)

const result=ref('')
const guess=()=>{
  count++;
  if(num.value>r){
    result.value='大了';
  }else if(num.value<r){
    result.value='小了';
  }else{
    result.value='你只用了'+count+'次就猜对了!';
  }
}
</script>


<style scoped>

</style>